<template>
  <div class="dashboard-container">
    <!-- 顶部标题和快速操作 -->
    <div class="dashboard-header">
      <h1>数据管理中心</h1>
      
    </div>

    <!-- 数据概览卡片 -->
    <div class="data-overview">
      <el-row :gutter="20">
        <el-col :span="8">
          <el-card shadow="hover" class="data-card">
            <div class="card-content">
              <div class="card-icon" style="background-color: #f0f7ff;">
                <el-icon color="#409EFF" :size="30"><TrendCharts /></el-icon>
              </div>
              <div class="card-text">
                <h3>互联网就业率</h3>
                <p class="value">87.5%</p>
                <p class="trend"><el-icon color="#67C23A"><Top /></el-icon> 同比上升 5.2%</p>
              </div>
            </div>
          </el-card>
        </el-col>
        <el-col :span="8">
          <el-card shadow="hover" class="data-card">
            <div class="card-content">
              <div class="card-icon" style="background-color: #f0f9eb;">
                <el-icon color="#67C23A" :size="30"><User /></el-icon>
              </div>
              <div class="card-text">
                <h3>新增就业人数</h3>
                <p class="value">1,245,678</p>
                <p class="trend"><el-icon color="#67C23A"><Top /></el-icon> 同比上升 12.3%</p>
              </div>
            </div>
          </el-card>
        </el-col>
        <el-col :span="8">
          <el-card shadow="hover" class="data-card">
            <div class="card-content">
              <div class="card-icon" style="background-color: #fdf6ec;">
                <el-icon color="#E6A23C" :size="30"><Money /></el-icon>
              </div>
              <div class="card-text">
                <h3>平均薪资</h3>
                <p class="value">¥15,800</p>
                <p class="trend"><el-icon color="#F56C6C"><Bottom /></el-icon> 同比下降 2.1%</p>
              </div>
            </div>
          </el-card>
        </el-col>
      </el-row>
    </div>

    <!-- 主要数据展示区域 -->
    <div class="main-content">
      <el-row :gutter="20">
        <!-- 行业就业率TOP3 -->
        <el-col :span="12">
          <el-card shadow="hover" class="chart-card">
            <template #header>
              <div class="card-header">
                <h3>互联网行业就业率TOP3</h3>
             
              </div>
            </template>
            <div class="chart-container">
              <div id="employmentRateChart" style="height: 300px;"></div>
            </div>
          </el-card>
        </el-col>

        <!-- 行业趋势分析 -->
        <el-col :span="12">
          <el-card shadow="hover" class="chart-card">
            <template #header>
              <div class="card-header">
                <h3>互联网行业趋势分析</h3>
              
              </div>
            </template>
            <div class="chart-container">
              <div id="industryTrendChart" style="height: 300px;"></div>
            </div>
          </el-card>
        </el-col>
      </el-row>

      <!-- 底部表格区域 -->
      <el-row :gutter="20" style="margin-top: 20px;">
        <el-col :span="24">
          <el-card shadow="hover">
            <template #header>
              <div class="card-header">
                <h3>各细分行业详细数据</h3>
               
              </div>
            </template>
            <el-table :data="filteredIndustryData" style="width: 100%" border>
              <el-table-column prop="industry" label="行业" width="180"></el-table-column>
              <el-table-column prop="employmentRate" label="就业率" sortable>
                <template #default="{row}">
                  <el-tag :type="getRateTagType(row.employmentRate)">{{ row.employmentRate }}%</el-tag>
                </template>
              </el-table-column>
              <el-table-column prop="avgSalary" label="平均薪资" sortable>
                <template #default="{row}">
                  ¥{{ row.avgSalary.toLocaleString() }}
                </template>
              </el-table-column>
              <el-table-column prop="jobOpenings" label="岗位缺口" sortable>
                <template #default="{row}">
                  {{ row.jobOpenings.toLocaleString() }}
                </template>
              </el-table-column>
              <el-table-column prop="growthRate" label="增长率" sortable>
                <template #default="{row}">
                  <span :style="{color: row.growthRate >= 0 ? '#67C23A' : '#F56C6C'}">
                    {{ row.growthRate >= 0 ? '+' : '' }}{{ row.growthRate }}%
                  </span>
                </template>
              </el-table-column>
             
            </el-table>
            <div class="pagination-container">
              <el-pagination
                :current-page="currentPage"
                :page-size="pageSize"
                :total="industryData.length"
                layout="prev, pager, next"
              ></el-pagination>
            </div>
          </el-card>
        </el-col>
      </el-row>
    </div>
  </div>
</template>

<script setup>
import { ref, computed, onMounted } from 'vue'
import * as echarts from 'echarts'
import {
  Search,
  TrendCharts,
  User,
  Money,
  Top,
  Bottom
} from '@element-plus/icons-vue'

// 数据定义
const timeRange = ref('1')
const trendType = ref('就业率')
const tableSearch = ref('')
const currentPage = ref(1)
const pageSize = ref(10)

const industryData = ref([
  { industry: '人工智能', employmentRate: 92.3, avgSalary: 18200, jobOpenings: 45678, growthRate: 15.2 },
  { industry: '大数据分析', employmentRate: 89.7, avgSalary: 16800, jobOpenings: 38921, growthRate: 12.5 },
  { industry: '云计算', employmentRate: 88.5, avgSalary: 17500, jobOpenings: 34215, growthRate: 18.3 },
  { industry: '前端开发', employmentRate: 85.2, avgSalary: 14200, jobOpenings: 56789, growthRate: 8.7 },
  { industry: '后端开发', employmentRate: 86.8, avgSalary: 15800, jobOpenings: 49876, growthRate: 9.5 },
  { industry: '移动开发', employmentRate: 84.3, avgSalary: 15200, jobOpenings: 32145, growthRate: 7.2 },
  { industry: '测试工程师', employmentRate: 82.6, avgSalary: 12800, jobOpenings: 28765, growthRate: 5.8 },
  { industry: '产品经理', employmentRate: 83.9, avgSalary: 16500, jobOpenings: 23456, growthRate: 10.3 },
  { industry: 'UI/UX设计', employmentRate: 81.5, avgSalary: 13800, jobOpenings: 19876, growthRate: 6.4 },
  { industry: '网络安全', employmentRate: 90.2, avgSalary: 19200, jobOpenings: 31234, growthRate: 20.1 }
])

// 计算属性
const filteredIndustryData = computed(() => {
  return industryData.value.filter(item => 
    item.industry.toLowerCase().includes(tableSearch.value.toLowerCase())
  )
})

// 方法
const getRateTagType = (rate) => {
  if (rate >= 90) return 'success'
  if (rate >= 85) return 'warning'
  return 'danger'
}

const refreshData = () => {
  // 实际项目中这里应该是API调用
  ElMessage.success('数据已刷新')
}

const exportData = () => {
  ElMessage.success('数据导出中...')
}

// 图表初始化
onMounted(() => {
  // 就业率TOP3图表
  const rateChart = echarts.init(document.getElementById('employmentRateChart'))
  rateChart.setOption({
    tooltip: {
      trigger: 'axis',
      axisPointer: {
        type: 'shadow'
      }
    },
    xAxis: {
      type: 'category',
      data: ['人工智能', '大数据分析', '云计算']
    },
    yAxis: {
      type: 'value',
      axisLabel: {
        formatter: '{value}%'
      }
    },
    series: [{
      data: [92.3, 89.7, 88.5],
      type: 'bar',
      itemStyle: {
        color: function(params) {
          const colorList = ['#409EFF', '#67C23A', '#E6A23C']
          return colorList[params.dataIndex]
        }
      },
      label: {
        show: true,
        position: 'top',
        formatter: '{c}%'
      }
    }]
  })

  // 行业趋势图表
  const trendChart = echarts.init(document.getElementById('industryTrendChart'))
  trendChart.setOption({
    tooltip: {
      trigger: 'axis'
    },
    legend: {
      data: ['人工智能', '大数据分析', '云计算']
    },
    xAxis: {
      type: 'category',
      boundaryGap: false,
      data: ['2020', '2021', '2022', '2023', '2024']
    },
    yAxis: {
      type: 'value',
      axisLabel: {
        formatter: '{value}%'
      }
    },
    series: [
      {
        name: '人工智能',
        type: 'line',
        data: [75, 78, 85, 88, 92],
        smooth: true,
        lineStyle: {
          width: 3
        }
      },
      {
        name: '大数据分析',
        type: 'line',
        data: [72, 76, 82, 86, 89],
        smooth: true,
        lineStyle: {
          width: 3
        }
      },
      {
        name: '云计算',
        type: 'line',
        data: [70, 74, 80, 84, 88],
        smooth: true,
        lineStyle: {
          width: 3
        }
      }
    ]
  })

  // 窗口大小变化时重绘图表
  window.addEventListener('resize', function() {
    rateChart.resize()
    trendChart.resize()
  })
})
</script>

<style scoped>
.dashboard-container {
  padding: 20px;
  background-color: #f5f7fa;
  min-height: 100vh;
}

.dashboard-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.dashboard-header h1 {
  font-size: 24px;
  color: #303133;
  margin: 0;
}

.data-overview {
  margin-bottom: 20px;
}

.data-card {
  margin-bottom: 20px;
  border-radius: 8px;
}

.card-content {
  display: flex;
  align-items: center;
}

.card-icon {
  width: 60px;
  height: 60px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-right: 20px;
}

.card-text h3 {
  margin: 0 0 8px 0;
  font-size: 16px;
  color: #909399;
}

.card-text .value {
  margin: 0;
  font-size: 24px;
  font-weight: bold;
  color: #303133;
}

.card-text .trend {
  margin: 4px 0 0 0;
  font-size: 12px;
  color: #909399;
  display: flex;
  align-items: center;
}

.main-content {
  margin-top: 20px;
}

.chart-card {
  margin-bottom: 20px;
  border-radius: 8px;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.card-header h3 {
  margin: 0;
  font-size: 16px;
}

.chart-container {
  width: 100%;
}

.pagination-container {
  margin-top: 20px;
  display: flex;
  justify-content: flex-end;
}

.el-table {
  margin-top: 10px;
}

.el-card {
  border-radius: 8px;
}
</style>